package com.tebiecloud.base.server.service;

import com.tebiecloud.base.client.constants.ResourceType;
import com.tebiecloud.base.client.model.AuthorityResource;
import com.tebiecloud.base.client.model.entity.BaseAuthority;
import com.tebiecloud.common.mybatis.base.service.IBaseService;
import com.tebiecloud.common.security.SecurityAuthority;

import java.util.Collection;
import java.util.List;

/**
 * 系统权限-菜单权限、操作权限、API权限 服务类
 * @author tebie
 * @date 2019-08-01
 */
public interface BaseAuthorityService extends IBaseService<BaseAuthority> {

    /**
     * 获取访问权限列表
     * @return
     */
    List<AuthorityResource> getAuthorityResourceList();

    /**
     * 获取开放对象权限
     * @param type = null 查询全部  type = 1 获取菜单和操作 type = 2 获取API
     * @return
     */
    List<SecurityAuthority> getSecurityAuthorityListByType(int type);

    /**
     * 获取应用已授权权限
     * @param appId
     * @return
     */
    List<SecurityAuthority> getSecurityAuthorityListByAppId(String appId);

    /**
     * 获取用户已授权权限
     * @param userId
     * @param root
     * @return
     */
    List<SecurityAuthority> getSecurityAuthorityList(Long userId, Boolean root);

    /**
     * 获取权限
     * @param resourceId
     * @param resourceType
     * @return
     */
    BaseAuthority getAuthority(Long resourceId, ResourceType resourceType);

    /**
     * 保存或修改权限
     * @param resourceId
     * @param resourceType
     * @return 权限Id
     */
    BaseAuthority saveOrUpdateAuthority(Long resourceId, ResourceType resourceType);

    /**
     * 清理无效权限
     * @param serviceId
     * @param codes
     */
    void clearInvalidApi(String serviceId, Collection<String> codes);

}
